<?php
class Memory extends CI_Controller {
	
	private $user_id;
	
	public function __construct()
	{
		parent::__construct();
		$this->user_utils->filter_login();
		$this->user_id = $this->user_utils->get_session_attribute(Variable::SESSION_USER_ID);
		
		$this->load->library('service/memory_service');
	}
	
	public function index($tag_id = 0)
	{
		$memory = $this->memory_service->get_last_schedule_memory($this->user_id, $tag_id);
		$data['memory'] = $memory;
		
		if($memory)
		{
			$record =  $this->record_model->get_record_by_id($memory->recordId);
			$data['record'] = $record;
		}
		
		$data['type'] = 'memory';
		$data['view'] = 'memory/memory';
		$this->load->view('member/index', $data);
	}
	
	public function update()
	{
		$memory_id = $this->input->post('memoryId');
		$is_remember = $this->input->post('remember');	
		
		if($is_remember) $score = Variable::SCORE_REMEMBER;
		else $score = Variable::SCORE_FORGOT;
		
		$this->memory_service->update_memory($memory_id, $score);
		redirect('memory');
	}
}
?>